libxenlight: add fuse around generic_device_add related to invalid kinds
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 14 Jan 2010 09:41:34 +0000 (09:41 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 14 Jan 2010 09:41:34 +0000 (09:41 +0000)
prevent segfault in case the backend or frontend kinds have
not been set to a correct kind value (or not initilized).

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl_device.c
tools/libxl/libxl_internal.h

index 7bbc924d180c9c9d7b42f4f2f87bd5443d3e5e89..726c54315614fa37974cc880ae58aba6c014ab29 100644 (file)
@@ -26,7 +26,7 @@
 #include "libxl.h"
 #include "libxl_internal.h"
 
-const char *string_of_kinds[] = {
+static const char *string_of_kinds[] = {
     [DEVICE_VIF] = "vif",
     [DEVICE_VBD] = "vbd",
     [DEVICE_TAP] = "tap",
@@ -45,6 +45,9 @@ int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
     struct xs_permissions backend_perms[2];
     struct xs_permissions hotplug_perms[1];
 
+    if (!is_valid_device_kind(device->backend_kind) || !is_valid_device_kind(device->kind))
+        return ERROR_INVAL;
+
     dom_path_backend = libxl_xs_get_dompath(ctx, device->backend_domid);
     dom_path = libxl_xs_get_dompath(ctx, device->domid);
 
index 11698bc04e4c9b7575c36dc28ba9c9f2ad97fb81..34f2e3825f5be0083d79205fcf719d076c8d3b3d 100644 (file)
@@ -68,7 +68,7 @@ typedef enum {
     DEVICE_CONSOLE,
 } libxl_device_kinds;
 
-extern const char *string_of_kinds[];
+#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
 
 typedef struct {
     uint32_t backend_devid;